#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; 

int n; 
int 

int main()
{
	long long pp, bb, b, p, k, s=1; 
	
	cin>>b>>p>>k; 
	pp = p; 
	bb = b; 
	while (p>0) {
		if (p&1)
			s = (s*b)%k; 
		b = (b*b)%k; 
		p >>= 1; 
	}
	s %= k; 
	cout<<bb<<"^"<<pp<<" mod "<<k<<"="<<s<<endl; 
	return 0; 
}

